package cn.wjdiankong.levideo.list.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import cn.wjdiankong.levideo.R;
import cn.wjdiankong.levideo.utils.UIUtil;

public class KuaishouFragmentListAdapter extends BaseFragmentListAdapter{
	
	private int defaultPicWidth;
	private int maxHeight;
	
	public KuaishouFragmentListAdapter(Context mContext, AbsListView listView, boolean isLocal){
		super(mContext, listView, isLocal);
		defaultPicWidth = UIUtil.getScreenWidth(mContext) - UIUtil.dip2px(mContext, 18);
		maxHeight =  UIUtil.dip2px(mContext, 300);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = super.getView(position, convertView, parent);
		ViewHolder viewHolder = (ViewHolder) view.getTag();
		if(TextUtils.isEmpty(dataList.get(position).filterUserNameStr)){
			viewHolder.userName.setText("昵称加载中...");
		}else{
			viewHolder.userName.setText(dataList.get(position).filterUserNameStr);
		}
		
		//瀑布流样式
		int w = dataList.get(position).videoWidth;
        int h = dataList.get(position).videoHeight;
        if(w != 0 && h != 0){
            ViewGroup.LayoutParams vl1 = viewHolder.imgV.getLayoutParams();
            vl1.width = this.defaultPicWidth;
            if(this.defaultPicWidth * h / w > this.maxHeight){
                vl1.height = this.maxHeight;
            }else{
                vl1.height = this.defaultPicWidth * h / w;
            }
            viewHolder.imgV.setLayoutParams(vl1);
        }
		
		return view;
	}

	@Override
	protected int getLayoutId() {
		return R.layout.fragment_kuaishou_adapter_item_layout;
	}
	
}
